/**
 * Created by 陈奇 on 2015/3/23.
 */
var express = require('express');
var router = express.Router();
var db = require('./conn'); //先引入数据库链接

router.get('/', function(req, resKinds) {
    db.pool.getConnection(function(err, connection) {
        var sql = 'select * from kindbook order by id+0';
        connection.query(sql, function(error, res) {
            var id = [] //书编号
            var name = []; //书名
            var img = []; //图片路径
            var author = []; //书的作者
            if (res.length != 0) {
                console.log(res[0].id);
                for (var i in res) {
                    id.push(res[i].id)
                    name.push(res[i].name);
                    img.push(res[i].img);
                    author.push(res[i].author);
                }
            }
            resKinds.render('kinds', {
                title: '在线阅读图书推荐',
                bookid: id,
                bookname: name,
                bookimg: img,
                bookauthor: author
            });
        });
        connection.release();
    });

});

module.exports = router;